﻿using System;
using System.Collections.Generic;
using System.Linq;
using DomenModel;
using System.Linq.Expressions;
using Model.Repositories.Interfaces;
using System.Data.Entity;

namespace OmsTestProject.MockRepository
{
    public class ItemRepository : IItemCrud
    {
        MockRepositoryContext _db = MockRepositoryContext.MockContextInstance;

        public void Deactivate(string Name) { }
        public void DeactivateById(int id) { }
        public long GetCountOfItems() { return 1; }
        public long GetCountOfItems(Expression<Func<Item, bool>> predicate) { return 1; }
        public List<Item> GetListForItemPagination(string a, string b)
        {
            return _db.Items;
        }
        public List<Item> GetListForPagination(int page, int itemsOnPage, Expression<Func<Item, string>> predicate, bool descending) { return new List<Item>(); }
        public List<Item> GetListForPaginationWithFilter(int page, int itemsOnPage, Expression<Func<Item, bool>> predicateListSelectedField, Expression<Func<Item, string>> predicateSortBy, bool descending) { return new List<Item>(); }
        




        public Item GetById(long Id)
        {
            Item itemById = _db.Items.FirstOrDefault(p => p.ItemId == Id);
            return itemById;
        }

        public void Save(Item t)
        {
            if (t.ItemId == 0)
            {
                t.ItemId = _db.Items.Count + 1;
            } 
            _db.Items.Add(t);
        }

        public void Update(Item t)
        {

            //_db.Items[t.ItemId].ItemDimensions = t.ItemDimensions;
            _db.Items[t.ItemId].Name = t.Name;
            _db.Items[t.ItemId].Description = t.Description;
            _db.Items[t.ItemId].ItemPrice = t.ItemPrice;
        }

        public void Delete(long Id)
        {
            Item itemById = _db.Items.FirstOrDefault(p => p.ItemId == Id);
            _db.Items.Remove(itemById);
        }

        public List<Item> GetCollection()
        {
                return _db.Items;
        }

        public List<Item> GetListForItemPagination(string a)
        {
            return _db.Items;
        }

        public IQueryable<Item> GetCollectionByFilter(Expression<Func<Item, bool>> t)
        {
                var itemByFilter = _db.Items.AsQueryable<Item>().Where(t);
                return itemByFilter;
        }

       
        public Item GetByName(string name)
        {
                Item itemByName = _db.Items.FirstOrDefault(p => p.Name == name);
                return itemByName;
        }

        public List<Item> GetListForPagination(string a, string b)
        {
            return null;
        }
    }
}
